home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10915 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  66 lines

  1. Path: newsxfer2.itd.umich.edu!caen!news-server!manowar
  2. From: manowar@engin.umich.edu (Krisztian Flautner)
  3. Newsgroups: comp.lang.c++
  4. Subject: Inheritance and function signatures
  5. Date: 11 Mar 1996 18:20:10 GMT
  6. Organization: University of Michigan
  7. Distribution: world
  8. Message-ID: <MANOWAR.96Mar11132010@dilo.engin.umich.edu>
  9. NNTP-Posting-Host: dilo.engin.umich.edu
  10.  
  11.  
  12.  
  13. Take the following example:
  14.  
  15.     #include <iostream.h>
  16.  
  17.  
  18.     class A {
  19.     public:
  20.         virtual void print();
  21.         virtual void print(int a, int b) = 0;
  22.     };
  23.  
  24.     class B : public A {
  25.     public:
  26.         void print(int a, int b);
  27.     };
  28.  
  29.  
  30.  
  31.  
  32.     void A::print()
  33.     {
  34.         cout << "A::print()" << endl;
  35.     }
  36.  
  37.     void B::print(int a, int b)
  38.     {
  39.         cout << "B::print(int " << a << ", int " << b << ")" << endl;
  40.     }
  41.  
  42.     main()
  43.     {
  44.         B* bb;
  45.  
  46.         bb = new B();
  47.  
  48.         bb->print();
  49.     }
  50.  
  51.  
  52. I was surprised to see that the call to bb->print() causes an error using
  53. several compilers. G++ produces the following error message:
  54.  
  55.     t.cc: In function `int main()':
  56.     t.cc:34: too few arguments for method `void B::print(int, int)'
  57.  
  58. It seems that function signitures are not properly inherited. Is this
  59. a bug or a feature ?
  60.  
  61.  
  62.  
  63. Thanks, -- Kris
  64.  
  65.  
  66.